package com.example.myapplication.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;

public class Adapter extends BaseAdapter {
    Context context;
    String[] usernames;
    String[] scores;
    String[] shuliangs;
    String[] jiages;
    int[] headImg;

    public Adapter(Context context, String[] usernames, String[] scores, String[] shuliangs, String[] jiages, int[] headImg) {
        this.context = context;
        this.usernames = usernames;
        this.scores = scores;
        this.shuliangs = shuliangs;
        this.jiages = jiages;
        this.headImg = headImg;
    }

    @Override
    public int getCount() {
        return usernames.length;
    }

    @Override
    public Object getItem(int position) {
        return usernames[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = View.inflate(context, R.layout.listview_item_layout, null);
            ImageView headImgs = convertView.findViewById(R.id.foot);
            TextView username = convertView.findViewById(R.id.name);
            TextView score = convertView.findViewById(R.id.content_tv);
            TextView jiage = convertView.findViewById(R.id.name2);
            ImageView jia = convertView.findViewById(R.id.jia);
            TextView shuliang = convertView.findViewById(R.id.jiage);
            ImageView jie = convertView.findViewById(R.id.jie);


            headImgs.setImageResource(headImg[position]);
            username.setText(usernames[position]);
            score.setText(scores[position]);
            jiage.setText(jiages[position]);
            jia.setImageResource(headImg[4]);
            shuliang.setText(shuliangs[position]);
            jie.setImageResource(headImg[5]);

        }
        return convertView;
    }

}